***** School type composition and performance, Table 3


tempname statistics
tempfile stats
postfile `statistics' ///
    str100 statistic count share soffer poffer y1diff y3diff using "`stats'", replace

	
*** Post admission shares and performance

clear
use "${data}cleaned_data_y3.dta"
do "${blocks}construct_new_variables"


	egen ns_mean_perc_y3 = mean(Percentage_y3), by(Course_NatSci_split)
	egen ns_sd_perc_y3   = sd(Percentage_y3), by(Course_NatSci_split)
	gen ns_std_perc_y3   = (Percentage_y3 - ns_mean_perc_y3) / ns_sd_perc_y3

	gen state_school=1 if SchoolType=="Maintained" & DomicileCat=="Home"
	replace state_school=0  if SchoolType=="Independent" & DomicileCat=="Home"

	su state_school 
	local share = r(mean)*100
	local count = r(N)

	ttest  ns_std_perc_y1, by(state_school)
	local y1diff=r(mu_2)-r(mu_1)

	ttest ns_std_perc_y3, by(state_school)
	local y3diff=r(mu_2)-r(mu_1)
	
	local soffer =.
	local poffer =.

 
	post `statistics' ("Mean") (`count') (`share') (`soffer') (`poffer') (`y1diff') (`y3diff')

	
	ci mean state_school 
	local share = r(se)*100
	local count = .
		
	local soffer =.
	local poffer =.
	
	ttest  ns_std_perc_y1, by(state_school)
	local y1diff=r(se)

	ttest  ns_std_perc_y3, by(state_school)
	local y3diff=r(se)

	post `statistics' ("Standard error")  (`count') (`share') (`soffer') (`poffer') (`y1diff') (`y3diff')
	
	*** Offer rates
	
	clear
	use "${data}merged_tripos.dta"
	
	keep if Course != "PBS"
	keep if Course != "Other"
	count
	
	keep if ApplyYear<=2016
	
	replace Offers = 0 if Offers != 1


	gen state_school=1 if SchoolType=="Maintained" & DomicileCat=="Home"
	replace state_school=0  if SchoolType=="Independent" & DomicileCat=="Home"

	
	*** Statistics
	
	local count=.
	local share=.
	
	su Offers if state_school==1
	local soffer = r(mean)*100
	
	su Offers if state_school==0
	local poffer = r(mean)*100
	
	local y1diff=.
	local y3diff=.
		
	post `statistics' ("Mean") (`count') (`share') (`soffer') (`poffer') (`y1diff') (`y3diff')

	local count=.
	local share=.
	
	ci mean Offers if state_school==1
	local soffer = r(se)*100
	
	ci mean Offers if state_school==0
	local poffer = r(se)*100
	
	local y1diff=.
	local y3diff=.	
	
	post `statistics' ("Standard error")  (`count') (`share') (`soffer') (`poffer') (`y1diff') (`y3diff')

	postclose `statistics'	


use `stats', clear
format *share %9.1fc

format soffer %9.1fc
format poffer %9.1fc
format *diff  %9.2fc

foreach x in s p {
sort statistic `x'offer 
by statistic: replace `x'offer=`x'offer[_n-1] if `x'offer==. & `x'offer[_n-1]~=. 
}


drop if count==. & share==.


listtab * using "${tables}descriptives_school.tex", ///
    rstyle(tabular) replace ///
    head("\begin{tabular}{@{\extracolsep{2pt}} l c c c c c c D{.}{.}{-3} D{.}{.}{-3}}" ///
    "\toprule" ///
    " & \multicolumn{1}{c}{\multirow{2}{*}{N}} & \multicolumn{1}{c}{\multirow{2}{*}{Percent state}} & \multicolumn{2}{c}{Offer probability} & \multicolumn{2}{c}{State score - Private score} \\" ///
	"\cmidrule(lr){4-5}\cmidrule(lr){6-7}" ///
	"& &  & \multicolumn{1}{c}{State} & \multicolumn{1}{c}{Private} & \multicolumn{1}{c}{Year 1} & \multicolumn{1}{c}{Year 3} \\  \midrule" "& (1) & (2) & (3) & (4) & (5) & (6) \\ \midrule") ///
    foot("\bottomrule" "\end{tabular}")

